package com.sxz.mall.mallsearch.thread;

import java.util.concurrent.*;

public class ThreadDemo {

    private static ExecutorService executorService = Executors.newFixedThreadPool(5);

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main方法执行了....");
        Tread01 tread01 = new Tread01();
        tread01.start();

        Thread02 thread02 = new Thread02();
        new Thread(thread02).start();

        new Thread(() -> {
            System.out.println("当前线程：" + Thread.currentThread().getName());
        }).start();

        // FutureTask本质是一个Callable接口
        FutureTask futureTask = new FutureTask(new MyCallable());
        Thread t3 = new Thread(futureTask);
        t3.start();

        // 阻塞
        Object object = futureTask.get();
        System.out.println("o=..." + object);

        executorService.execute(() -> {
            System.out.println("线程池 当前线程：" + Thread.currentThread().getName());


        });

        System.out.println("main方法结束了....");

    }
}

class Tread01 extends Thread {
    @Override
    public void run() {
        System.out.println("当前线程：" + Thread.currentThread().getName());
    }
}

class Thread02 implements Runnable {
    @Override
    public void run() {
        System.out.println("当前线程：" + Thread.currentThread().getName());
    }
}

class MyCallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {

        System.out.println("当前线程：" + Thread.currentThread().getName());
        return 10;
    }
}